package com.egg.ylt.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.egg.ylt.R;
import com.egg.ylt.pojo.NatatoriumListPageEntity;
import com.yonyou.framework.library.adapter.rv.CommonAdapter;
import com.yonyou.framework.library.adapter.rv.ViewHolder;

import static com.umeng.socialize.utils.ContextUtil.getContext;

/**
 * author:        yupeng
 * created on:    2019/2/26 10:54
 * description:   选择商店列表适配器
 */
public class ADA_SelectShopList extends CommonAdapter<NatatoriumListPageEntity.ListBean> {
    private Activity activity;

    public ADA_SelectShopList(Activity activity) {
        super(activity);
        this.activity = activity;
    }

    @Override
    protected int itemLayoutId() {
        return R.layout.item_select_shop;
    }

    @Override
    protected void convert(ViewHolder holder, final NatatoriumListPageEntity.ListBean listBean, int position) {
        Glide.with(getContext())
                .load(listBean.getLogoUrl())
                .centerCrop()
                .dontAnimate()
                //.placeholder(R.mipmap.default_user_icon)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into((ImageView) holder.getView(R.id.shop_icon_riv));

        holder.setText(R.id.shop_name_txt, listBean.getName());
        holder.setText(R.id.shop_address_txt, listBean.getAddress());
        holder.setText(R.id.shop_distance_txt, listBean.getDistance()+"m");

        holder.setOnClickListener(R.id.select_button, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("ShopModel", listBean);
                activity.setResult(Activity.RESULT_OK, intent);
                activity.finish();
            }
        });

        holder.getView(R.id.divider).setVisibility(position == getItemCount()? View.GONE : View.VISIBLE);
    }
}
